import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';


@Injectable()
export class AuthService {
  constructor(
    private readonly jwtService: JwtService,
  ) {}

  async validateUser(userinfo): Promise<any> {
    const { username } = userinfo;
    return {
      id: 1,
      username: username,
    };
  }
  async login(user: any): Promise<any> {
    const payload = { username: user.username, id: user.id }; // 把信息存在token
    const access_token = this.jwtService.sign(payload);
    return {
      access_token
    };
  }
}
